package com.yoga.manager.app.impl;

import com.yoga.common.appexception.AppErrorCodeEnum;
import com.yoga.common.appexception.AppException;
import com.yoga.common.bo.NoticeMessageBO;
import com.yoga.common.page.PageBO;
import com.yoga.common.qto.NoticeMessageQTO;
import com.yoga.dao.dao.NoticeMessageDao;
import com.yoga.manager.app.AppNoticeMessageManager;
import com.yoga.manager.beanUtil.NoticeMessageBeanUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by hdx on 2020/10/19.
 */
@Component
public class AppNoticeMessageManagerImpl implements AppNoticeMessageManager {
    Logger logger = LoggerFactory.getLogger(AppNoticeMessageManagerImpl.class);

    @Resource
    private NoticeMessageDao messageDao;

    @Override
    public PageBO<NoticeMessageBO> findForPage(NoticeMessageQTO messageQTO) throws AppException {
        if (messageQTO == null) {
            throw new AppException(AppErrorCodeEnum.PARAMETER_NULL);
        }
        PageBO<NoticeMessageBO> pageBO = new PageBO<>();
        pageBO.setQuery(messageQTO);
        Integer count = messageDao.findForPageCount(messageQTO);
        if (count == null || count <= 0) {
            return pageBO;
        }
        List<NoticeMessageBO> boList = NoticeMessageBeanUtil.doList2BOList(messageDao.findForPage(messageQTO));
        pageBO.setTotalCount(count);
        pageBO.setData(boList);

        return pageBO;
    }
}
